package com.gjs.demo002;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.gjs.demo002.adapter.MyRecyclerAdapter;
import com.gjs.demo002.bean.RecyclerBean;


import java.util.ArrayList;
import java.util.List;

public class RecyclerViewDemoActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private List<RecyclerBean> list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_view_demo);
        initView();
    }

    private void initView() {
        recyclerView = findViewById(R.id.recycler_demo);
        List<RecyclerBean> list = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            RecyclerBean recyclerBean = new RecyclerBean();
            recyclerBean.setTitle("第"+(i+1)+"个****");
            list.add(recyclerBean);
        }

        MyRecyclerAdapter adapter = new MyRecyclerAdapter(list,this);
        recyclerView.setAdapter(adapter);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); // 设置横向滑动
        recyclerView.setLayoutManager(linearLayoutManager);
    }
}


